Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ic-ledger-types): Add AccountIdentifier.as_bytes() #520

Merged
merged 2 commits into from
Sep 25, 2024

Conversation

bitdivine
Copy link
Member

@bitdivine bitdivine commented Sep 25, 2024

Description

It is currently not possible to obtain an AccountIdentifier as bytes. It is only possible to obtain hex and then convert the hex back to bytes. This is resolved by adding an .as_bytes() method that returns a reference to the inner bytes.

Fixes #519

How Has This Been Tested?

A unit test is included that verifies that parsing bytes and returning them as bytes yields the original data.

Checklist:

  • The title of this PR complies with Conventional Commits.
  • I have edited the CHANGELOG accordingly.
  • I have made corresponding changes to the documentation.
    • Rustdoc is included on the method.

@bitdivine bitdivine marked this pull request as ready for review September 25, 2024 04:35
@bitdivine bitdivine requested a review from a team as a code owner September 25, 2024 04:35
#[test]
fn check_round_trip() {
fn check_hex_round_trip() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to avoid ambiguity around hex/bytes round trip.

/// Provide the account identifier as bytes.
pub fn as_bytes(&self) -> &[u8; 32] {
&self.0
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: The constructor takes great care to make sure that the checksum is valid, so this method is provided, rather than making the inner value public and compromising the integrity checks.

A fixed length array is returned rather than a slice, as otherwise the caller has no guarantee that the length is correct.

@adamspofford-dfinity adamspofford-dfinity merged commit 882fa28 into main Sep 25, 2024
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature request: Get AccountIdentifier as bytes
2 participants